package com.hq.date;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Demo {
    public static void main(String[] args) throws ParseException {
        String str="2019-01-01 10:10:10";

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = simpleDateFormat.parse(str);
        System.out.println(parse);

        Date date = new Date();
        String format = simpleDateFormat.format(date);
        System.out.println(format);

        boolean before = date.after(parse);
        System.out.println(before);

        String s = formatDate3(date);
        System.out.println(s);

    }

//    private static final ThreadLocal<DateFormat> df= ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd"));

    private static ThreadLocal<SimpleDateFormat> formatCache = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

    public static String formatDate3(Date date) {
        SimpleDateFormat format = formatCache.get();
        return format.format(date);
    }
}
